const {
	$U_UserInfo,
	$U_LocalUserInfo,
	$U_SetItem,
	$U_GetItem,
	$U_RemoveItem,
} = require('@utils/storage')
const {
	updateMethod,
	recordPassword,
} = require('./info-methods')

module.exports = function() {
	let {
		infoComp,
	} = $['components-jq']
	infoComp.pwdComp = $("#info-password")
	infoComp.changePwdComp = $("#info-password-change")
	infoComp.recordPwdComp = $("#info-record-pwd")
	infoComp.emailComp = $("#info-email")
	infoComp.changeEmailComp = $("#info-email-change")
	infoComp.nicknameComp = $("#info-nickname")
	infoComp.changeNickNameComp = $("#info-nickname-change")

	let userInfo = $U_UserInfo()
	let localUserInfo = $U_LocalUserInfo()
	infoComp.pwdComp.passwordbox({
		showEye: true,
		value: userInfo.orgPassword || '',
	})
	infoComp.emailComp.textbox({
		value: userInfo.email || '',
	})
	infoComp.nicknameComp.textbox({
		value: userInfo.nickname || '',
	})
	infoComp.changePwdComp.linkbutton({
		iconCls: 'icon-reload',
		plain: true,
		onClick() {
			updateMethod.call(infoComp, 'pwd')
		},
	})
	infoComp.recordPwdComp.switchbutton({
		checked: !!(userInfo.account == localUserInfo.account && localUserInfo.orgPassword),
		onText: '是',
		offText: '否',
		onChange(checked) {
			recordPassword.call(infoComp, checked)
		},
	})
	infoComp.changeEmailComp.linkbutton({
		iconCls: 'icon-reload',
		plain: true,
		onClick() {
			updateMethod.call(infoComp, 'email')
		},
	})
	infoComp.changeNickNameComp.linkbutton({
		iconCls: 'icon-reload',
		plain: true,
		onClick() {
			updateMethod.call(infoComp, 'nickname')
		},
	})
}